package cn.net.mugui.net.pc.panel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;

import com.mugui.Dui.DButton;
import com.mugui.Dui.DDialog;
import com.mugui.base.base.Autowired;
import com.mugui.base.base.Component;

import cn.net.mugui.net.pc.manager.FunctionUI;
import cn.net.mugui.net.pc.panel.comp.TMWindows;
import cn.net.mugui.net.pc.task.TMBiliTask;
import lombok.Getter;

/**
 * b站弹幕管理
 * 
 * @author 木鬼
 *
 */
@Component
public class BilibiliPanel extends FunctionUI {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7060674933539600888L;

	public BilibiliPanel() {
		setTitle("b站弹幕管理");
		setMenu_name("b站弹幕管理");
		setLayout(new BorderLayout(0, 0));

		JPanel panel = new JPanel();
		add(panel, BorderLayout.NORTH);

		DButton button = new DButton("开启弹幕显示窗口", (Color) null);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (e.getActionCommand().equals("开启弹幕显示窗口")) {
					button.setText("关闭弹幕显示窗口");
					openTMWindows();
				} else {
					button.setText("开启弹幕显示窗口");
					closeTMWindows();
				}
			}
		});
		panel.add(button);
	}

	/**
	 * 关闭窗口
	 */
	protected void closeTMWindows() {
		dialog.dispose();
		tmWindows.quit();
		tmBiliTask.stop();
	}

	@Getter
	DDialog dialog = null;

	@Autowired
	TMWindows tmWindows;

	public static Dimension win_size = Toolkit.getDefaultToolkit().getScreenSize();
	/**
	 * 开启窗口
	 */
	protected void openTMWindows() {
		if(dialog==null) {
			dialog = new DDialog(null, "弹幕", false);
			dialog.add(tmWindows);
			dialog.setUndecorated(true);
			dialog.setAlwaysOnTop(true);
			
			dialog.setKai(win_size.width, win_size.height);
			dialog.getContentPane().setBackground(null);
		}
		tmWindows.init();
		tmBiliTask.start();
		dialog.setVisible(true);
	}
	@Autowired
	TMBiliTask tmBiliTask;

	@Override
	public void init() {
	}

	@Override
	public void quit() {
	}

	@Override
	public void dataInit() {
	}

	@Override
	public void dataSave() {
	}

}
